<?php

namespace app\common\model\circle;

use think\Model;


class Log extends Model
{
	// 设置当前模型使用的完整数据库连接信息
	protected $connection = 'database.db_second';//连接配置
    // 表名
    protected $name = 'circle_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'circle_state_text',
        'trends_state_text',
        'create_time_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getCircleStateList()
    {
        return ['1' => __('移出圈子'), '2' => __('互动封禁'), '3' => __('移出加入黑名单'), '4' => __('设为管理员'), '5' => __('设为吧主'), '6' => __('降为圈友'), '7' => __('互动解封'), '8' => __('拉黑解禁')];
    }

    public function getTrendsStateList()
    {
        return ['2' => __('违规警告'), '3' => __('降级为圈友'), '4' => __('移动到黑名单')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCircleStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['circle_state']) ? $data['circle_state'] : '');
        $list = $this->getCircleStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTrendsStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['trends_state']) ? $data['trends_state'] : '');
        $list = $this->getTrendsStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

	public function user2()
	{
		return $this->belongsTo('app\common\model\User', 'user2_id', 'id', [], 'LEFT')->setEagerlyType(0);
	}


	public function trends()
    {
        return $this->belongsTo('app\common\model\Trends', 'trends_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
